package alpha.com.google.code.mechanic.janitor.ui.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import alpha.com.google.code.mechanic.janitor.ui.ImportContextDialog;

/**
 * 
 * The class is to handle the command of the menu item "Import". The command
 * allows users import configuration files of one Contexts in a zip file 
 * at a time. When the users import the Contexts, the information of the 
 * Context will be added to the context.con file and users can choose whether
 * to activate the imported Context. 
 * 
 * @Last_edited: Oct 31, 2014
 * 
 * @author jingjiejiang
 * @since Oct 31, 2014
 */
public class ImportHandler extends AbstractHandler {

  public Object execute(ExecutionEvent event) throws ExecutionException {
    
    Shell pshell = Display.getCurrent().getActiveShell();
    
    ImportContextDialog dialog = new ImportContextDialog(pshell);
    int dialogopen = dialog.open();
    if (Dialog.OK == dialogopen) {
      
      dialog.close();
    } 
    else if (Dialog.CANCEL == dialogopen) {
      
      dialog.close();
    }
    
    return null;
  }

}
